home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / bgui12.lha / demos / cxdemo.c < prev    next >
C/C++ Source or Header  |  1995-04-23  |  13KB  |  221 lines

  1. ;/* Execute me to compile with DICE V3.0.
  2. dcc cxdemo.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6. **      CXDEMO.C
  7. **
  8. **      (C) Copyright 1995 Jaba Development.
  9. **      (C) Copyright 1995 Jan van den Baard.
  10. **          All Rights Reserved.
  11. **/
  12.  
  13. #include "democode.h"
  14.  
  15. /*
  16. **      Key ID.
  17. **/
  18. #define CX_F1_PRESSED           1L
  19.  
  20. /*
  21. **      Gadget ID's.
  22. **/
  23. #define ID_HIDE                 1L
  24. #define ID_QUIT                 2L
  25.  
  26. /*
  27. **      Information text.
  28. **/
  29. UBYTE *InfoTxt = ISEQ_C ISEQ_B ISEQ_HIGHLIGHT
  30.                  "CxDemo\n\n" ISEQ_TEXT ISEQ_N
  31.                  "This is a small \"do-nothing\" example of how\n"
  32.                  "to use the BGUI commodity class.\n"
  33.                  "In this example F1 is the Hotkey used to\n"
  34.                  "signal the broker to open the window.";
  35.  
  36. VOID StartDemo( void )
  37. {
  38.         Object          *CM_Broker, *WN_Window, *GA_Hide, *GA_Quit;
  39.         ULONG            signal = 0L, winsig = 0L, sigrec, type, id, rc;
  40.         BOOL             running = TRUE;
  41.  
  42.         /*
  43.         **      Setup a commodity object.
  44.         **/
  45.         CM_Broker = CommodityObject,
  46.                 COMM_Name,              "CxDemo",
  47.                 COMM_Title,             "Simple BGUI broker.",
  48.                 COMM_Description,       "Does not do anything usefull.",
  49.                 COMM_ShowHide,          TRUE,
  50.         EndObject;
  51.  
  52.         /*
  53.         **      Object OK?
  54.         **/
  55.         if ( CM_Broker ) {
  56.                 /*
  57.                 **      Create a small window.
  58.                 **/
  59.                 WN_Window = WindowObject,
  60.                         WINDOW_Title,           "CxDemo",
  61.                         WINDOW_RMBTrap,         TRUE,
  62.                         WINDOW_SizeGadget,      FALSE,  /* No use in this window. */
  63.                         WINDOW_AutoAspect,      TRUE,
  64.                         WINDOW_MasterGroup,
  65.                                 VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  66.                                         StartMember,
  67.                                                 InfoObject, ButtonFrame,
  68.                                                         FRM_Flags,              FRF_RECESSED,
  69.                                                         INFO_TextFormat,        InfoTxt,
  70.                                                         INFO_FixTextWidth,      TRUE,
  71.                                                         INFO_MinLines,          6,
  72.                                                 EndObject,
  73.                                         EndMember,
  74.                                         StartMember,
  75.                                                 HGroupObject, Spacing( 4 ),
  76.                                                         StartMember, GA_Hide = KeyButton( "_Hide", ID_HIDE ), EndMember,
  77.                                                         VarSpace( DEFAULT_WEIGHT ),
  78.                                                         StartMember, GA_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  79.                                                 EndObject, FixMinHeight,
  80.                                         EndMember,
  81.                                 EndObject,
  82.                 EndObject;
  83.  
  84.                 /*
  85.                 **      Window OK?
  86.                 **/
  87.                 if ( WN_Window ) {
  88.                         /*
  89.                         **      Add F1 as hotkey.
  90.                         **/
  91.                         if ( AddHotkey( CM_Broker, "f1", CX_F1_PRESSED, 0L )) {
  92.                                 /*
  93.                                 **      Add gadget keys.
  94.                                 **/
  95.                                 GadgetKey( WN_Window, GA_Hide, "h" );
  96.                                 GadgetKey( WN_Window, GA_Quit, "q" );
  97.                                 /*
  98.                                 **      Obtain broker signal mask.
  99.                                 **/
  100.                                 GetAttr( COMM_SigMask, CM_Broker, &signal );
  101.                                 /*
  102.                                 **      Activate the broker.
  103.                                 **/
  104.                                 EnableBroker( CM_Broker );
  105.                                 /*
  106.                                 **      Open up the window.
  107.                                 **/
  108.                                 if ( WindowOpen( WN_Window )) {
  109.                                         /*
  110.                                         **      Obtain window sigmask.
  111.                                         **/
  112.                                         GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  113.                                         /*
  114.                                         **      Wait for messages.
  115.                                         **/
  116.                                         do {
  117.                                                 sigrec = Wait( signal | winsig | SIGBREAKF_CTRL_C );
  118.                                                 /*
  119.                                                 **      Broker signal?
  120.                                                 **/
  121.                                                 if ( sigrec & signal ) {
  122.                                                         /*
  123.                                                         **      Obtain the messages from the
  124.                                                         **      broker.
  125.                                                         **/
  126.                                                         while ( MsgInfo( CM_Broker, &type, &id, NULL ) != CMMI_NOMORE ) {
  127.                                                                 /*
  128.                                                                 **      Evaluate message.
  129.                                                                 **/
  130.                                                                 switch ( type ) {
  131.  
  132.                                                                         case    CXM_IEVENT:
  133.                                                                                 switch ( id ) {
  134.  
  135.                                                                                         case    CX_F1_PRESSED:
  136.                                                                                                 goto openUp;
  137.                                                                                 }
  138.                                                                                 break;
  139.  
  140.                                                                         case    CXM_COMMAND:
  141.                                                                                 switch ( id ) {
  142.  
  143.                                                                                         case    CXCMD_KILL:
  144.                                                                                                 Tell( "bye bye\n" );
  145.                                                                                                 running = FALSE;
  146.                                                                                                 break;
  147.  
  148.                                                                                         case    CXCMD_DISABLE:
  149.                                                                                                 Tell( "broker disabled\n" );
  150.                                                                                                 DisableBroker( CM_Broker );
  151.                                                                                                 break;
  152.  
  153.                                                                                         case    CXCMD_ENABLE:
  154.                                                                                                 Tell( "broker enabled\n" );
  155.                                                                                                 EnableBroker( CM_Broker );
  156.                                                                                                 break;
  157.  
  158.                                                                                         case    CXCMD_UNIQUE:
  159.                                                                                         case    CXCMD_APPEAR:
  160.                                                                                                 openUp:
  161.                                                                                                 if ( WindowOpen( WN_Window ))
  162.                                                                                                         GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  163.                                                                                                 break;
  164.  
  165.                                                                                         case    CXCMD_DISAPPEAR:
  166.                                                                                                 WindowClose( WN_Window );
  167.                                                                                                 winsig = 0L;
  168.                                                                                                 break;
  169.                                                                                 }
  170.                                                                                 break;
  171.                                                                 }
  172.                                                         }
  173.                                                 }
  174.  
  175.                                                 /*
  176.                                                 **      Window signal?
  177.                                                 **/
  178.                                                 if ( sigrec & winsig ) {
  179.                                                         while ( WN_Window && (( rc = HandleEvent( WN_Window )) != WMHI_NOMORE )) {
  180.                                                                 switch ( rc ) {
  181.  
  182.                                                                         case    ID_HIDE:
  183.                                                                         case    WMHI_CLOSEWINDOW:
  184.                                                                                 /*
  185.                                                                                 **      Hide the window.
  186.                                                                                 **/
  187.                                                                                 WindowClose( WN_Window );
  188.                                                                                 winsig = 0L;
  189.                                                                                 break;
  190.  
  191.                                                                         case    ID_QUIT:
  192.                                                                                 /*
  193.                                                                                 **      The end.
  194.                                                                                 **/
  195.                                                                                 Tell( "bye bye\n" );
  196.                                                                                 running = FALSE;
  197.                                                                                 break;
  198.                                                                 }
  199.                                                         }
  200.                                                 }
  201.  
  202.                                                 /*
  203.                                                 **      CTRL+C?
  204.                                                 **/
  205.                                                 if ( sigrec & SIGBREAKF_CTRL_C ) {
  206.                                                         Tell( "bye bye\n" );
  207.                                                         running = FALSE;
  208.                                                 }
  209.                                         } while ( running );
  210.                                 } else
  211.                                         Tell( "unable to open the window\n" );
  212.                         } else
  213.                                 Tell( "unable to add the hotkey\n" );
  214.                         DisposeObject( WN_Window );
  215.                 } else
  216.                         Tell( "unable to create a window object\n" );
  217.                 DisposeObject( CM_Broker );
  218.         } else
  219.                 Tell( "unable to create a commodity object\n" );
  220. }
  221.